home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / util / checkat.c++ < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  94 lines

  1. #include "Str.h"
  2. #include <time.h>
  3.  
  4. extern "C" int parseAtSyntax(const char*, const struct tm&, struct tm&, char* emsg);
  5.  
  6. static const char* days[] = {
  7.     "Sunday", "Monday", "Tuesday", "Wednesday",
  8.     "Thursday", "Friday", "Saturday"
  9. };
  10. static const char* months[] = {
  11.     "January", "February", "March", "April", "May", "June", "July",
  12.     "August", "September", "October", "November", "December"
  13. };
  14.  
  15. static void
  16. print(const char* tag, const struct tm& t)
  17. {
  18.     printf("%-24s: %s %s %u, %u %u:%02u:%02u (%u yday)\n",
  19.     tag,
  20.     days[t.tm_wday],
  21.     months[t.tm_mon], t.tm_mday, 1900+t.tm_year,
  22.     t.tm_hour, t.tm_min, t.tm_sec,
  23.     t.tm_yday
  24.     );
  25. }
  26.  
  27. static void
  28. doit(const char* s)
  29. {
  30.     time_t t = time(0);
  31.     struct tm now = *localtime(&t);
  32.     struct tm at;
  33.     char emsg[1024];
  34.     if (parseAtSyntax(s, now, at, emsg))
  35.     print(s, at);
  36.     else
  37.     printf("%-24s: %s.\n", s, emsg);
  38. }
  39.  
  40. int
  41. main(int argc, char* argv[])
  42. {
  43.     if (argc == 1) {
  44.     doit("8");
  45.     doit("10");
  46.     doit("80");
  47.     doit("1100");
  48.     doit("2300zulu");
  49.     doit("8pm");
  50.     doit("8am");
  51.     doit("10am");
  52.     doit("10pm");
  53.     doit("0815am");
  54.     doit("8:15am");
  55.     doit("now");
  56.     doit("noon");
  57.     doit("midnight");
  58.     doit("next");
  59.     doit("0815am Jan 24");
  60.     doit("8:15am Jan 24");
  61.     doit("1:30 today");
  62.     doit("1:30 tomorrow");
  63.     doit("midnight Monday");
  64.     doit("midnight mon");
  65.     doit("next Tuesday");
  66.     doit("next tue");
  67.     doit("noon Wednesday");
  68.     doit("noon wed");
  69.     doit("next Thursday");
  70.     doit("next thu");
  71.     doit("8pm Friday");
  72.     doit("8pm fri");
  73.     doit("5 pm Friday");
  74.     doit("6am Saturday");
  75.     doit("6am sat");
  76.     doit("7:30 Sunday");
  77.     doit("7:30 sun");
  78.     doit("8:15am Jan 24, 1993");
  79.     doit("8:15am Jan 24, 1994");
  80.     doit("now + 1 minute");
  81.     doit("now + 1 hour");
  82.     doit("now + 1 day");
  83.     doit("now + 1 week");
  84.     doit("now + 1 month");
  85.     doit("now + 1 year");
  86.     } else {
  87.     fxStr s;
  88.     for (int i = 1; i < argc; i++)
  89.         s = s | " " | fxStr(argv[i]);
  90.     doit(s);
  91.     }
  92.     return (0);
  93. }
  94.